package com.ipc.app.web.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ipc.app.biz.InformationBiz;
import com.ipc.app.constants.InformationTypeConstants;
import com.ipc.app.model.Information;
import com.ipc.app.model.Paginator;

/**
 * @author haijie.zhang
 * 
 */
@Controller
@RequestMapping(value = "/jsp/inCitySearch.do")
public class InCitySearchAction {

	@Autowired
	private InformationBiz informationBiz;

	@RequestMapping(method = RequestMethod.GET)
	public String view() {
		return "inCitySearch";
	}

	@RequestMapping(method = RequestMethod.POST)
	public String inCitySearch(ModelMap model, String depX, String depY,
			String desX, String desY, String pageIndex) {
		if (StringUtils.isBlank(pageIndex)) {
			pageIndex = "1";
		}
		Paginator<Information> informations = informationBiz
				.getInformationByDepAndDes(depX, depY, desX, desY,
						InformationTypeConstants.CAR_OWNER, Integer
								.valueOf(pageIndex));

		model.addAttribute("informations", informations);
		return "inCitySearchResult";
	}
}
